package com.zretc.controller;

import com.zretc.entity.ProductCollect;
import com.zretc.service.ProductCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/productCollectController")
public class ProductCollectController {

    @Autowired
    private ProductCollectService productCollectService;

    /**
     * 添加产品收藏
     *
     * @param productCollect 产品对象
     * @return
     */
    @RequestMapping("/insertProduct")
    @ResponseBody
    public boolean insertProduct(ProductCollect productCollect) {
        int n = productCollectService.saveProductCollect(productCollect);
        if (n > 0) {
            return true;
        }
        return false;
    }

    /**
     * 删除商品收藏
     *
     * @param productCollectId
     * @return
     */
    @RequestMapping("/deleteProduct")
    @ResponseBody
    public boolean deleteProduct(int productCollectId) {
        int n = productCollectService.deleteProductCollectByCollectId(productCollectId);
        if (n > 0) {
            return true;
        }
        return false;
    }

    /**
     * 查询所有的产品收藏
     *
     * @return
     */
    @RequestMapping("/getAllProductList")
    List<ProductCollect> getAllProductList() {
        List<ProductCollect> productCollectList = productCollectService.getyAllProductCollectList();
        return productCollectList;

    }

    /**
     * 通过商品收藏编号查询收藏信息
     *
     * @param productCollectId 收藏编号
     * @return
     */
    @RequestMapping("/getProductCollectByCollectIdList")
    @ResponseBody
    ProductCollect getProductCollectByCollectIdList(Integer productCollectId) {
        ProductCollect productCollect = productCollectService.getProductCollectList(productCollectId);
        return productCollect;
    }

}
